<template>
  <el-container class="hone-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" alt />
        <span>保险管理系统</span>
        <em>v1.0</em>
      </div>
      <el-button type="info" @click="signOut">退出</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse? '64px':'200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :router="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          unique-opened
        >
          <el-submenu :index="index +' '" v-for="(item,index) in saleDate" :key="item.index">
            <template slot="title">
              <i class="el-icon-location"></i>
              <!-- 文本 -->
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children">
              <!-- @click="saveNavState('/'+subItem.path)" -->
              <template slot="title">
                <!-- 图标 -->
                <i :class="subItem.icon"></i>
                <!-- 文本 -->
                <span>{{subItem.name}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapActions, mapMutations } = createNamespacedHelpers("home");

export default {
  data() {
    return {
      isCollapse: true,
    };
  },
  computed: {
    ...mapState(["saleDate"]),
  },
  methods: {
    // 点击折叠或展开菜单
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    signOut() {
      localStorage.token = "";
      alert("退出");
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="less" scoped>
.hone-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      border: 2px solid gray;
      background-color: #fff;
      box-sizing: border-box;
      padding-top: 8px;
    }
    span {
      margin-left: 10px;
    }
    em {
      color: gray;
      font-size: 14px;
      margin-top: 7px;
      margin-left: 8px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border: 0;
  }
}
.el-main {
  background-color: #eaedf1;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>